<template>
  <div class="container">
    <!-- 系统日志 -->
    <!-- 查询条件 -->
    <el-form :inline="true" class="tableSearchBox" size="medium">
      <el-form-item label="时间：">
        <el-date-picker
          v-model="search.time"
          type="date"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          placeholder="选择日期"
          :editable="false"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="日志类型：">
        <el-select v-model="search.type" clearable placeholder="请选择类型">
          <el-option
            v-for="(item,index) in typeList"
            :key="index"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="getData">查询</el-button>
      </el-form-item>
    </el-form>
    <!-- /查询条件 -->
    <PagesTable
      :isIndex="true"
      :tableHeader="tableHeader"
      :tableData="tableData"
      :tableOperation="tableOperation"
      :tablePagination="tablePagination"
      @pageSize="pageSizeChange"
      @currentPage="currentPageChange"
    />
  </div>
</template>

<script>
import PagesTable from "../../components/PagesTable.vue";
export default {
  components: {
    PagesTable
  },
  data() {
    return {
      search: {
        //搜索条件
        time: new Date().format("yyyy-MM-dd"),
        type: ""
      },
      typeList: [],
      tableHeader: [
        {
          name: "日志内容",
          mark: "log",
          minWidth: "90"
        },
        {
          name: "用户IP",
          mark: "ip",
          minWidth: "90"
        },
        {
          name: "操作时间",
          mark: "time",
          minWidth: "90"
        },
        {
          name: "操作员",
          mark: "user",
          minWidth: "90"
        }
      ],
      tableOperation: [],
      tablePagination: {
        show: true,
        current: 1,
        size: 10,
        total: 0
      },
      tableData: [],
      tableDataAll: [],
      tableDataSearch: []
    };
  },
  async mounted() {
    // await this.getType();
    // await this.getData();

    this.tableData=[
      {log:"登录系统",time:"2024-07-18 15:01:00",ip:"192.168.10.18",user:"贾芳"},
      {log:"抄表",time:"2024-07-18 16:21:00",ip:"192.168.10.18",user:"贾芳"},
      {log:"抄表",time:"2024-07-19 09:05:00",ip:"192.168.10.18",user:"贾芳"},
      {log:"登录系统",time:"2024-07-20 11:05:00",ip:"192.168.10.18",user:"贾芳"},
      {log:"登录系统",time:"2024-07-21 14:09:00",ip:"192.168.10.18",user:"贾芳"},
    ]
    this.tablePagination.total=this.tableData.length
  },
  beforeDestroy() {},
  created() {},
  methods: {
    async getType() {
      const self = this;
      await self.$axios.post("/service/c0000000/nqgp41dg").then(res => {
        if (res.data.status === "success") {
          var typeList = res.data.res;
          self.typeList = typeList;
          self.search.type = typeList[0].id;
        } else {
          self.$message.error(res.data.res);
        }
      });
    },
    async getData() {
      const self = this;
      var param = {
        time: self.search.time,
        ltpid: self.search.type
      };
      await self.$axios.post("/service/c0000000/sykonofu", param).then(res => {
        if (res.data.status === "success") {
          self.tableDataAll = res.data.res;
          self.tableDataAll.forEach(element => {
            element.log = element.sName + " " + element.ext;
          });
          self.tableDataSearch = self.tableDataAll;
          self.tablePagination.total = self.tableDataSearch.length;
          self.handleTableData();
        } else {
          self.$message.error(res.data.res);
        }
      });
    },
    handleTableData() {
      const self = this;
      self.tableData = [];
      let i = (self.tablePagination.current - 1) * self.tablePagination.size;
      let j = self.tablePagination.current * self.tablePagination.size;
      if (j > self.tablePagination.total) {
        j = self.tablePagination.total;
      }
      for (i; i < j; i++) {
        self.tableData.push(self.tableDataSearch[i]);
      }
    },
    pageSizeChange(data) {
      this.tablePagination.size = data;
      this.handleTableData();
    },
    currentPageChange(data) {
      this.tablePagination.current = data;
      this.handleTableData();
    }
  }
};
</script>
<style lang="scss" scoped>
</style>